Repository navigation
Update hh ledger - #8674
Update hh ledger#8674ChristopherDedominici wants to merge 5 commits into
Conversation
🦋 Changeset detectedLatest commit: b9d5914 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
hardhatTotal size of the bundle: List of dependencies (sorted by size) |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Lossy numeric inputs can be signed incorrectly, and in-flight device connections can outlive connection closure.
Review effort: Balanced
Findings: 1
Open (6)
Make pending connection attempts cancellable on close · New Reject JSON numeric tokens that lose precision before parsing · New Validate chain IDs exactly before converting to Number · New Resolve unresolved cross-reference placeholder · New Remove nonexistent reminder from manual test expectations · New Document all payloads sent by metadata and transaction checks · New
What changed in this PR
Migrates hardhat-ledger from deprecated LedgerJS packages to Ledger’s Device Management Kit while preserving existing RPC behavior.
Changes:
- Adds DMK device discovery, action, error, signing, and cleanup infrastructure.
- Strengthens typed-data validation and post-signature verification.
- Closes Ignition and example-script network connections and documents lifecycle/privacy changes.
| File | Description |
|---|---|
.changeset/ignition-close-network-connection.md |
Records Ignition connection cleanup. |
.changeset/ledger-device-management-kit.md |
Records the DMK migration. |
.github/actions/setup-env/action.yml |
Updates the native dependency comment. |
MY_DOC.md |
Documents migration design and impacts. |
cspell.dictionary.txt |
Adds migration-related terms. |
packages/example-project/scripts/ledger-2.ts |
Adds extensive manual Ledger QA scenarios. |
packages/example-project/scripts/ledger.ts |
Closes the example connection. |
packages/hardhat-ignition/src/internal/tasks/deploy.ts |
Closes deployment connections. |
packages/hardhat-ignition/src/internal/tasks/track-tx.ts |
Closes transaction-tracking connections. |
packages/hardhat-ignition/src/internal/tasks/verify.ts |
Closes verification connections. |
packages/hardhat-ledger/README.md |
Documents DMK behavior and cleanup. |
packages/hardhat-ledger/package.json |
Replaces LedgerJS with DMK dependencies. |
packages/hardhat-ledger/src/internal/cjs-imports.ts |
Removes the LedgerJS import bridge. |
packages/hardhat-ledger/src/internal/connect-device.ts |
Manages DMK sessions and transport cleanup. |
packages/hardhat-ledger/src/internal/derivation-path.ts |
Normalizes paths for DMK. |
packages/hardhat-ledger/src/internal/discover-device.ts |
Implements polling device discovery. |
packages/hardhat-ledger/src/internal/dmk-errors.ts |
Normalizes and classifies DMK errors. |
packages/hardhat-ledger/src/internal/dmk-imports.ts |
Adds the CommonJS DMK import bridge. |
packages/hardhat-ledger/src/internal/get-y-parity.ts |
Rejects unsafe signature values. |
packages/hardhat-ledger/src/internal/handler.ts |
Migrates signing and lifecycle handling to DMK. |
packages/hardhat-ledger/src/internal/hook-handlers/network.ts |
Cleans up handlers when connections close. |
packages/hardhat-ledger/src/internal/run-device-action.ts |
Converts DMK observables into promises. |
packages/hardhat-ledger/src/internal/typed-data.ts |
Parses and validates typed data. |
packages/hardhat-ledger/src/internal/types.ts |
Defines DMK-facing abstractions. |
packages/hardhat-ledger/test/helpers/dmk-error-classes.ts |
Exposes real DMK error classes to tests. |
packages/hardhat-ledger/test/helpers/eth-mocked.ts |
Removes the LedgerJS Ethereum mock. |
packages/hardhat-ledger/test/helpers/ledger-device-mock.ts |
Adds a DMK device and signer mock. |
packages/hardhat-ledger/test/helpers/tests-cjs-imports.ts |
Removes obsolete test imports. |
packages/hardhat-ledger/test/helpers/transport-node-hid-mock.ts |
Removes the old transport mock. |
packages/hardhat-ledger/test/internal/derivation-path.ts |
Tests path normalization. |
packages/hardhat-ledger/test/internal/discover-device.ts |
Tests discovery and cleanup behavior. |
packages/hardhat-ledger/test/internal/dmk-errors.ts |
Tests DMK error handling. |
packages/hardhat-ledger/test/internal/run-device-action.ts |
Tests observable action handling. |
packages/hardhat-ledger/test/internal/typed-data.ts |
Tests typed-data validation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| this.#device = await this.#deviceFactory( | ||
| reconnecting | ||
| ? LedgerHandler.RECONNECTION_TIMEOUT | ||
| : LedgerHandler.DEFAULT_TIMEOUT, | ||
| ); |
| const parsed = Number(chainId); | ||
|
|
||
| if (Number.isSafeInteger(parsed)) { | ||
| return parsed; | ||
| } |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Typed-data verification can use signer-mutated input, and the verify task still leaves delegated verification connections open.
Review effort: Balanced
Findings: 1
Open (9)
Make pending connection attempts cancellable on close Close connections created during contract verification · New Preserve immutable typed data before signer mutation · New Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Update stale Ledger support release note · New Document all payloads sent by metadata and transaction checks Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Concurrent reconnection can replace or close the wrong session, and the design document contains unresolved links.
Review effort: Balanced
Findings: 2
Open (10)
Coordinate reconnect resets with initialization mutex · New Make pending connection attempts cancellable on close Preserve immutable typed data before signer mutation Close connections created during contract verification Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Update stale Ledger support release note Document all payloads sent by metadata and transaction checks Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
| await this.#resetConnection(); | ||
| await this.#initializationMutex.exclusiveRun( | ||
| async () => await this.#initExclusive(0, true), | ||
| ); |
There was a problem hiding this comment.
🟡 Changes recommended
Core DMK teardown lacks automated coverage, and the added design document contains unresolved placeholders and decisions.
8 open findings
Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Add lifecycle tests for concurrent sessions and teardown · New Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
3 resolved since last review
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| export function closeDeviceManagementKit(): void { | ||
| if (deviceManagementKit === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| if (liveDeviceSessions > 0) { |
There was a problem hiding this comment.
🔵 Needs a closer look
Typed-data declarations can bypass malformed-text validation, and closing during path derivation reports the wrong error.
8 open findings
Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
Previously missed (2)
In code that hasn't changed since last review

Preserve connection errors during derivation

packages/hardhat-ledger/src/internal/handler.ts:439
Closing the connection while getAddress is running makes #runOnDevice throw the intended CONNECTION_ERROR, but this catch does not preserve it: it falls through and wraps it as ERROR_WHILE_DERIVING_PATH. This makes close-during-derivation report the wrong failure, unlike close during signing. Re-throw once the handler is closed before applying derivation error classification.

Validate EIP-712 field, type, and primary type names

packages/hardhat-ledger/src/internal/typed-data.ts:50
This validates only domain/message values, but EIP-712 field and type names are also encoded into the digest. A lone surrogate in types[*].name, types[*].type, or primaryType therefore reaches both encoders and can be normalized even though the submitted text has no UTF-8 representation—the exact case this check is intended to reject. Walk the declarations and primary type too.
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
There was a problem hiding this comment.
🟡 Changes recommended
The DMK import seam omits an imported runtime export, causing a compile failure, and its critical cleanup path lacks automated coverage.
9 open findings
Re-export NodeHidTransport from the CommonJS module · New Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
There was a problem hiding this comment.
🟡 Changes recommended
Typed-data validation, close-time error propagation, and manual QA expectations contain unresolved correctness issues.
15 open findings
Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Parameterize expected errors for hashable invalid-data cases · New Reject non-canonical integer syntax before chain ID conversion Preserve connection errors during path discovery cancellation Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Update stale app-opening guidance in connection error messages Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
🧠 Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Typed-data verification can reuse DMK-mutated input, discovery can leak timers, and several QA assertions contradict the implementation.
17 open findings
Route synchronous device errors through cleanup settlement · New Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Update assertion for CONNECTION_CLOSED errors · New Parameterize expected errors for hashable invalid-data cases Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Update stale node-gyp dependency description · New Update stale app-opening guidance in connection error messages Remove nonexistent reminder from manual test expectations Resolve unresolved cross-reference placeholder
1 resolved since last review
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Previously missed (1)
In code that hasn't changed since last review

Translate LedgerDeviceError to HardhatError publicly

packages/hardhat-ledger/src/internal/run-device-action.ts:102
This newly authored LedgerDeviceError is rejected directly to callers (the handler test at lines 611–617 explicitly requires that), but production Hardhat code surfaces failures as HardhatErrors rather than custom Error subclasses. Keep the tagged wrapper for internal classification if needed, then translate it to an appropriate HardhatError at the public boundary; the stopped/no-device paths should follow the same rule.
🧠 Review effort: Balanced
| const listening = listenToAvailableDevices().subscribe(observer); | ||
|
|
||
| if (settled) { | ||
| // A replayed device settled before `subscription` was assigned. | ||
| listening.unsubscribe(); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| subscription = listening; |
There was a problem hiding this comment.
🟡 Changes recommended
The native fallback build can fail without node-gyp, and the user documentation remains incomplete and inconsistent.
16 open findings
Route synchronous device errors through cleanup settlement Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Retain node-gyp as a direct dependency · New Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Close DMK connections in usage examples · New Update stale node-gyp dependency description Update stale app-opening guidance in connection error messages Resolve unresolved cross-reference placeholder
3 resolved since last review
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
🧠 Review effort: Balanced
c6218da to
3bbaf94
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Typed-data mutation and chain-ID normalization can verify or sign data different from the caller’s original request, alongside dependency and messaging issues.
16 open findings
Route synchronous device errors through cleanup settlement Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Retain node-gyp as a direct dependency Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Close DMK connections in usage examples Update stale node-gyp dependency description Update stale app-opening guidance in connection error messages Resolve unresolved cross-reference placeholder
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Previously missed (2)
In code that hasn't changed since last review

Remove outdated instruction to manually open the Ethereum app

packages/hardhat-errors/src/descriptors.ts:3378
This updated connection error still tells users to open the Ethereum app, although the DMK now opens it automatically and the new retry messages intentionally removed that instruction. Keeping it in both the CLI message and website description gives misleading remediation for connection failures.

Correctly document rxjs as a runtime dependency

MY_DOC.md:103
The statement that rxjs is imported only for types is incorrect: run-device-action.ts imports and executes takeWhile at runtime. Describe its runtime role so this design record matches the implementation.
🧠 Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Typed-data verification currently reuses an object that the signer mutates, undermining the signature-integrity check.
17 open findings
Route synchronous device errors through cleanup settlement Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Retain node-gyp as a direct dependency Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Correct dependency rationale for RxJS runtime import · New Close DMK connections in usage examples Update stale node-gyp dependency description Update stale app-opening guidance in connection error messages Resolve unresolved cross-reference placeholder
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
🧠 Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Typed-data integrity, chain-ID validation, and closed-connection concurrency issues remain unresolved.
18 open findings
Route synchronous device errors through cleanup settlement Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Retain node-gyp as a direct dependency Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Remove EIP-7702 from the documented non-goals · New Correct dependency rationale for RxJS runtime import Close DMK connections in usage examples Update stale node-gyp dependency description Update stale app-opening guidance in connection error messages Resolve unresolved cross-reference placeholder
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Previously missed (2)
In code that hasn't changed since last review

Reject requests using cached handlers on closed connections

packages/hardhat-ledger/src/internal/hook-handlers/network.ts:67
The closed check only runs when no handler is cached. closeConnection marks the connection closed before awaiting handler.close(), but leaves the existing handler in this map until that await finishes, so a concurrent eth_accounts request can retrieve it and succeed on a closed connection. Check closedConnections before using either a cached or new handler.

Convert terminal failures to HardhatErrors

packages/hardhat-ledger/src/internal/run-device-action.ts:105
These terminal paths reject locally created CustomError instances, and LedgerHandler lets device-action failures escape to callers. Production errors in this repository are required to be HardhatErrors so callers receive a stable descriptor and normal Hardhat formatting; add descriptors and convert these failures before they escape.
🧠 Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Typed-data verification can use mutated input, lossy chain IDs are accepted, and verification-created connections remain unclosed.
14 open findings
Route synchronous device errors through cleanup settlement Reject cyclic values during EIP-712 validation Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Retain node-gyp as a direct dependency Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Preserve immutable typed data before signer mutation Validate chain IDs exactly before converting to Number Reject JSON numeric tokens that lose precision before parsing Close DMK connections in usage examples Update stale app-opening guidance in connection error messages
4 resolved since last review
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
🧠 Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Typed-data normalization, discovery cleanup, and verification connection handling contain unresolved correctness and lifecycle issues.
10 open findings
Route synchronous device errors through cleanup settlement Export NodeHidTransport from the DMK import seam Coordinate reconnect resets with initialization mutex Make pending connection attempts cancellable on close Correct expected error type for refused-device confirmation · New Reject non-canonical integer syntax before chain ID conversion Validate surrogate pairs in all EIP-712 encoded strings Add lifecycle tests for concurrent sessions and teardown Validate chain IDs exactly before converting to Number Update stale app-opening guidance in connection error messages
5 resolved since last review
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
🧠 Review effort: Balanced
| async function rejectOnDevice(): Promise<void> { | ||
| expected( | ||
| "'[hardhat-ledger] Confirmation failure', then the DMK error reaches " + | ||
| "the script as is: a tagged error, not a HardhatError, which Hardhat " + | ||
| "prints as 'An unexpected error occurred:' with its stack. There was " + | ||
| "no retry and no reconnection, and the process exits after the close.", | ||
| ); |

MVP, closed in favor of: #8706